﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace SEORank
{
    /// <summary>
    /// 代理服务器助手
    /// </summary>
    public static class ProxyHelper
    {
        /// <summary>
        /// 代理服务器列表
        /// </summary>
        public static List<Proxy> Proxys = new List<Proxy>() {
            new Proxy() { Host = "127.0.0.1", Port = 8580 },
        };

        ///// <summary>
        ///// 是否启用代理服务器
        ///// </summary>
        //public static bool UseProxy { get; set; }

        /// <summary>
        /// 获取一个代理服务器
        /// </summary>
        /// <returns></returns>
        public static Proxy GetProxy()
        {
            foreach (Proxy p in Proxys)
            {
                if (p.Enabled)
                {
                    //WebProxy wp = new WebProxy(p.Host, p.Port);


                    return p;

                    //IpAddress ip = HttpHelper.GetIP(p);

                    //if (ip != null)
                    //{
                    //    Console.WriteLine(p.Host + "," + p.Port + "," + ip.IP + "," + ip.Address);
                    //    return p;
                    //    //break;
                    //}
                    //else
                    //{
                    //    p.Enabled = false;
                    //    continue;
                    //}

                    //string html = "", error = "";
                    //html = HttpHelper.Get("https://www.google.com/", out error, proxy);

                    //if (string.IsNullOrWhiteSpace(error) && html.Contains("Google"))
                    //{
                    //    Console.WriteLine(p.Host + "," + p.Port);
                    //    break;
                    //}
                    //else
                    //{
                    //    p.Enabled = false;
                    //    continue;
                    //}
                }
            }

            return null;
        }

    }
}
